﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CodeCamp12.Domain;
using CodeCamp12.BLL;

namespace CodeCamp12
{
    /// <summary>
    /// Summary description for GetImageForSponsor
    /// </summary>
    public class GetImageForSponsor : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            var sponsorBuissProvider = new SponsorsBL();
            var sponsorList = sponsorBuissProvider.GetAllSponsors();
            var current = HttpContext.Current;
            var id = current.Request.QueryString["id"];
            foreach (var s in sponsorList)
            {
                if (s.ID.ToString().Equals(id))
                {
                    var data = new byte[s.SponsorImage.Length];
                    s.SponsorImage.Read(data, 0, (int)s.SponsorImage.Length);
                    s.SponsorImage.Dispose();
                    context.Response.Clear();
                    context.Response.BinaryWrite(data);
                    return;
                }
            }   
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}